﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using RepositoryUnit.Data.Entity;

namespace RepositoryUnit.Data
{
    public class MyDbContext : DbContext
    {
        public MyDbContext()
        {
        }

        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseLoggerFactory(ConsoloLogggerFactory);
            //optionsBuilder.UseLoggerFactory(ConsoloLogggerFactory)
            //    .UseSqlServer(@"Server=.;Database=MVCTest;Integrated Security=True");
        }

        public static readonly ILoggerFactory ConsoloLogggerFactory =
        LoggerFactory.Create(builder =>
       {
           builder.AddFilter((category, level) =>
                category == DbLoggerCategory.Database.Command.Name
                && level == LogLevel.Information)
               .AddConsole();
       });

        public DbSet<Student> Student { get; set; }

        public DbSet<TbUser> TbUsers { get; set; }

        public DbSet<User> User { get; set; }

        public DbSet<Teacher> Teacher { get; set; }
    }
}